package com.wonders.frame.repository;

import com.wonders.frame.entity.AuthOrga;
import com.wonders.frame.entity.AuthPermission;
import com.wonders.frame.repository.core.CoreRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AuthOrgaRepository extends CoreRepository<AuthOrga> {

    @Query("select d from AuthOrga d where orgaCode=:orgaCode and removed = 0 ")
    List<AuthOrga> checkUnique(@Param("orgaCode") String orgaCode);

    @Query("select d from AuthOrga d where id=:id and removed = 0 ")
    AuthOrga getOneAuthOrgaById(@Param("id") String id);

    @Query("select d from AuthOrga d where removed = 0 order by d.seq ")
    List<AuthOrga> getAllAuthOrga();

    @Query(value = "select d from AuthOrga d where d.removed = 0 and d.orgaSerachindex like CONCAT('%',:id,'%') order by d.seq ")
    List<AuthOrga> findLikeOrgaTree(@Param("id") String id);

    AuthOrga findByIdAndRemoved(String id, Integer removed);

    @Query("select d from AuthOrga d where id=:id or parentId=:id and removed = 0 ")
    List<AuthOrga> findByIdAndRemoved(@Param("id") String id);

    List<AuthOrga> findByParentIdAndRemoved(String id, Integer removed);

    List<AuthOrga> findByParentId(String id);

    AuthOrga findByOrgaPropertyAndRemoved(String orgaProperty, Integer removed);

    List<AuthOrga> findByOrgaNameLikeAndRemoved(String Orga_name,Integer removed);

}
